package com.ioidea.base.util

object StringUtils {

    /**
     * 转换高低位
     */
    fun reverseHexString(hexString: String): String {
        val reversedHex = StringBuilder()
        for (i in hexString.length - 2 downTo 0 step 2) {
            reversedHex.append(hexString.substring(i, i + 2))
        }
        return reversedHex.toString()
    }


    /**
     * 解析上报数据的版本号
     */
    fun covertVersionString(hexString: String): String {
        val reversedHex = StringBuilder()
        println("hexString.length:" + hexString.length)
        var i = 0
        while (i <= hexString.length - 2) {
            val value = hexString.substring(i, i + 2)
            val decimalValue = value.toInt(16)
            if (i == 0) {
                reversedHex.append("V").append(decimalValue).append(".")
            } else if (i == hexString.length - 2) {
                reversedHex.append(decimalValue)
            } else {
                reversedHex.append(decimalValue).append(".")
            }
            i += 2
        }
        return reversedHex.toString()
    }
}